package sdu.icat.ltp.tool;

import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class TextBreaker {

    public static String[] TextBreak(String text) {
	BreakIterator bi = BreakIterator.getSentenceInstance(Locale.CHINA);
	bi.setText(text);
	
	int bindex = bi.first();
	List<Integer> br = new ArrayList<Integer>();
	while(bindex != bi.DONE) {
	    br.add(bindex);
	    bindex = bi.next();
	}
	String[] vars = new String[br.size()];
	for(int i=0,j=0;i<br.size();i++) {
	    vars[i]=text.substring(j,br.get(i));
	    if(i>0 && vars[i].endsWith("\\t\\n")) {
		vars[i]=vars[i].substring(0,vars.length-2);
	    }
	    j=br.get(i);
	}
	
	return vars;
    }
    
}
